## Copyright (c) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
cmake_minimum_required(VERSION 3.5.1)

set(DEPTH "../../")

set(GPA_PROJECT_NAME GPUPerfAPICounterGenerator-Common)
set(ProjectName ${GPA_PROJECT_NAME})

include(${GPA_CMAKE_MODULES_DIR}/common.cmake)
include(${CMAKE_COMMON_LIB_GLOBAL_AMD_ADL})
include(${CMAKE_COMMON_SRC_GLOBAL_ADL_UTIL})
include(${CMAKE_COMMON_SRC_GLOBAL_TSINGLETON})
include(${CMAKE_COMMON_SRC_GLOBAL_DEVICE_INFO})

if(WIN32)
    include(${CMAKE_COMMON_LIB_GLOBAL_EXT_WINDOWS_SDK})
endif()

set(CMAKE_INCLUDE_CURRENT_DIR ON)
include_directories(${GPA_SRC_COMMON}
                    ${GPA_PUBLIC_HEADER}
                    ${GPA_AUTOGEN_SRC_COUNTER_GENERATOR}
                    ${ADDITIONAL_COUNTER_DIR_INCLUDE})

set(COUNTER_GENERATOR_VS_FILTER CounterGenerators)
set(COUNTER_SCHEDULER_VS_FILTER CounterSchedulers)
set(HARDWARE_COUNTER_VS_FILTER HardwareCounters)
set(DERIVED_COUNTER_VS_FILTER DerivedCounters)
set(COUNTER_SPLITTING_ALGO_VS_FILTER CounterSplittingAlgorithms)

set(INTERNALLY_EXPOSED_HEADERS
    gpa_counter_generator.h
    gpa_counter_accessor_interface.h
    gpa_counter_scheduler_interface.h)

set(COUNTER_GENERATOR_HEADERS
    gpa_counter_generator_base.h
    gpa_counter_generator_scheduler_manager.h
    gpa_sw_counter_manager.h)

set(COUNTER_GENERATOR_SRC
    gpa_counter_generator.cc
    gpa_counter_generator_base.cc
    gpa_counter_generator_scheduler_manager.cc
    gpa_sw_counter_manager.cc)

set(COUNTER_SCHEDULER_HEADERS
    gpa_counter_scheduler_base.h)

set(COUNTER_SCHEDULER_SRC
    gpa_counter_scheduler_base.cc)

    set(HARDWARE_COUNTER_HEADERS
    gpa_counter_group_accessor.h
    gpa_counter.h)

if(NOT DEFINED COUNTER_DIR)
    set(AUTOGEN_COUNTER_DIR ${GPA_AUTOGEN_SRC_COUNTER_GENERATOR})
    set(COUNTER_DIR ${CMAKE_CURRENT_LIST_DIR})
endif()

if(EXISTS ${GPA_AUTOGEN_SRC_COUNTER_GENERATOR})
    include(${GPA_AUTOGEN_SRC_COUNTER_GENERATOR}/gpa_hw_counter.cmake)
    include(${GPA_AUTOGEN_SRC_COUNTER_GENERATOR}/gpa_hw_exposed_counters.cmake)
endif()

set(HARDWARE_COUNTER_SRC ${HW_COUNTER_HEADERS}
                         ${ADDITIONAL_COUNTER_GEN_SOURCES})

set(HARDWARE_EXPOSED_COUNTER ${HW_EXPOSED_COUNTER_HEADERS} ${HW_EXPOSED_COUNTER_SRC})

if(EXISTS ${AUTOGEN_COUNTER_DIR})
    include(${AUTOGEN_COUNTER_DIR}/gpa_hw_counter.cmake)
endif()

set(HARDWARE_COUNTER_SRC ${HARDWARE_COUNTER_SRC} ${HW_COUNTER_SRC})

set(DERIVED_COUNTER_HEADERS
    gpa_derived_counter.h
    gpa_derived_counter_evaluator.inc)

set(DERIVED_COUNTER_SRC
    gpa_derived_counter.cc)

set(COUNTER_SPLITTING_ALGO_HEADERS
    gpa_split_counter_factory.h
    gpa_split_counters_consolidated.h
    gpa_split_counters_interfaces.h
    gpa_split_counters_max_per_pass.h
    gpa_split_counters_one_per_pass.h)

set(COUNTER_HEADERS
    gpa_hardware_counters.h
    gpa_software_counters.h)

set(COMMON_HEADER_FILES ${HEADER_FILES}
    ${INTERNALLY_EXPOSED_HEADERS}
    ${COUNTER_GENERATOR_HEADERS}
    ${COUNTER_SCHEDULER_HEADERS}
    ${HARDWARE_COUNTER_HEADERS}
    ${DERIVED_COUNTER_HEADERS}
    ${COUNTER_SPLITTING_ALGO_HEADERS}
    ${COUNTER_HEADERS})

set(COMMON_SOURCE_FILES ${SOURCE_FILES}
    ${COUNTER_GENERATOR_SRC}
    ${COUNTER_SCHEDULER_SRC}
    ${HARDWARE_COUNTER_SRC}
    ${DERIVED_COUNTER_SRC}
    ${HARDWARE_EXPOSED_COUNTER})

set(SOURCES ${COMMON_HEADER_FILES} ${COMMON_SOURCE_FILES})

if(WIN32)
    source_group("Internally Exposed Header Files" FILES ${INTERNALLY_EXPOSED_HEADERS})
    source_group("Source Files\\${COUNTER_GENERATOR_VS_FILTER}" FILES ${COUNTER_GENERATOR_HEADERS} ${COUNTER_GENERATOR_SRC})
    source_group("Source Files\\${COUNTER_SCHEDULER_VS_FILTER}" FILES ${COUNTER_SCHEDULER_HEADERS} ${COUNTER_SCHEDULER_SRC})
    source_group("Source Files\\${HARDWARE_COUNTER_VS_FILTER}" FILES ${HARDWARE_COUNTER_HEADERS})
    source_group("Source Files\\${HARDWARE_COUNTER_VS_FILTER}\\AutoGenerated" FILES ${HW_COUNTER_HEADERS} ${HW_COUNTER_SRC})
    source_group("Source Files\\${DERIVED_COUNTER_VS_FILTER}" FILES ${DERIVED_COUNTER_HEADERS} ${DERIVED_COUNTER_SRC})
    source_group("Source Files\\${COUNTER_SPLITTING_ALGO_VS_FILTER}" FILES ${COUNTER_SPLITTING_ALGO_HEADERS})
    source_group("Source Files\\${HARDWARE_COUNTER_VS_FILTER}\\AutoGenerated" FILES ${HARDWARE_EXPOSED_COUNTER})
    source_group("Source Files" FILES ${COUNTER_HEADERS})
endif()

if(WIN32)
    add_compile_options(/bigobj)
 else()
     add_compile_options(-Wno-write-strings)
 endif()

add_library(${GPA_PROJECT_NAME} ${SOURCES})
target_include_directories(${GPA_PROJECT_NAME} PUBLIC ${ADDITIONAL_INCLUDE_DIRECTORIES})




